﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace GameAndNode_updated
{
    

    class Keyboard
    {
        public event EventHandler KeyLeft;
        public event EventHandler KeyRigth;
        public event EventHandler KeyDown;
        public event EventHandler KeyUp;

        

        protected virtual void OnKeyLeft()
        {
            if (KeyLeft!=null)
            {
                KeyLeft(this, EventArgs.Empty);
            }
        }

        protected virtual void OnKeyRigth()
        {
            if (KeyRigth != null)
            {
                KeyRigth(this, EventArgs.Empty);
            }
        }

        protected virtual void OnKeyDown()
        {
            if (KeyDown != null)
            {
                KeyDown(this, EventArgs.Empty);
            }
        }

        protected virtual void OnKeyUp()
        {
            if (KeyUp != null)
            {
                KeyUp(this, EventArgs.Empty);
            }
        }

        public void ControlKeyboard(ConsoleKeyInfo key)
        {
            
                switch (key.Key)
                {
                    case ConsoleKey.LeftArrow:
                        {
                            OnKeyLeft();
                            break;
                        }
                    case ConsoleKey.RightArrow:
                        {
                            OnKeyRigth();
                            break;
                        }
                    case ConsoleKey.DownArrow:
                        {
                            OnKeyDown();
                            break;
                        }
                    case ConsoleKey.UpArrow:
                        {
                            OnKeyUp();
                            break;
                        }
                }
            
        }

    }
}
